package com.duan.luren.simpleQueue;

import com.duan.luren.ConnectionHelper;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;

/**
 * 简单队列发送消息
 */
public class SimpleQueueProducer {
    //定义队列的名称
    public static final String QueueName = "test_simple_queue";

    public static void main(String[] args) {
        try (Connection connection = ConnectionHelper.getConnection()){
            Channel channel = connection.createChannel();

            channel.queueDeclare(QueueName, false, false, false, null);
            for (int i = 0; i < 10; i++) {
                String message = "Hello World " + i;
                channel.basicPublish("", QueueName, null, message.getBytes("UTF-8"));
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
